@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
@endsection
@section('content')
    <link rel="stylesheet" href="/lib/layer/theme/default/layer.css"/>
    <script type="text/javascript" src="/lib/layer/layer.js"></script>
    <style>
        .showClass{
            color:red;
        }
    </style>
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li><a href="/train/course">组合课程活动</a></li>
                <li class="active">期数列表</li>
            </ul>
        </div>
        <div class="main-content">
            <div class="btn-toolbar list-toolbar">
                <form class="form-inline" action="" method="get">
                    <a href="/train/periods/add?id={{$id}}"><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" ><i class="fa fa-plus"></i> 新增</button></a>
                </form>
            </div>

            <div class="row not_live_list" style="">
                <div class="col-sm-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading no-collapse">课程列表</div>
                        <table class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>期数名称</th>
                                <th>期号</th>
                                <th>开班时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($periods as $period)
                                <tr id="courseClass_">
                                    <td>{{$period->id}}</td>
                                    <td>{{$period->name}}</td>
                                    <td>{{$period->stage}}</td>
                                    <td>{{$period->begin_time}}</td>
                                    <td class="text-justify" style="width:30%;">
                                        <a class="btn btn-info btn-xs {{$period->is_show==1?'showClass':''}}" onclick="setUqinueShows(this)" data-id="{{$period->id}}" data-show="{{$period->is_show}}">{{$period->is_show==1?'已设唯一显示':'设置唯一显示'}}</a>
                                        <a class="btn btn-success btn-xs" href="/train/periods/edit?id={{$period->id}}">编辑</a>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            {{$periods->render()}}
        </div>
    </div>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">课程列表</h4>
                </div>
                <div class="modal-body"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var page = 1;
        function courseList(obj){
            var id = $(obj).attr('data-id');
            var data = {id:id,page:page};
            $.ajax({
                url:'/train/course/list',
                data:data,
                type:'GET',
                dataType:'json',
                success:function(res){
                    $('#myModal .modal-body').html(res.body);
                    $('#myModal').modal('show');
                }
            })
        }
        function setUqinueShows(obj){
            var id = $(obj).attr('data-id');
            var is_show = $(obj).attr('data-show');
            var message = '';
            if(is_show == 0){
                is_show = 1;
                message = '已设唯一显示'
                $(obj).addClass('showClass');
            }else{
                is_show = 0;
                message = '设置唯一显示';
                $(obj).removeClass('showClass');
            }

            $(obj).text(message);
            $(obj).attr('data-show',is_show);
            var token = '{{csrf_token()}}';
            var data = {id:id,is_show:is_show,_token:token};
            $.ajax({
                url:'/train/periods/setShow',
                data:data,
                type:'POST',
                dataType:'json',
                success:function(res){
                    console.log(res);
                    if(res.code == 0){
                        swal(res.message);
                    }
                }
            })
        }
    </script>
@endsection